package org.bao.bestmatch.model;

/**
 * definition of Module.it's the model of data in MS-EXCEL files.
 * @author baoxiwu<bb@feijiao.info>,Cell&Module,BOE DT
 * @version 0.9.0
 * @since 2010-11-19
 * @license LGPL
 * 
 */
public class Module {
	public static final int MODULE_TYPE_TFT = 0;
	public static final int MODULE_TYPE_CF = 1;
	
	private int type = Module.MODULE_TYPE_TFT;
	private String cst_id = null;
	private String glass_id = null;
	private String grade = null;
	
	public Module(){
		//empty
	}
	
	public Module(int type, String cst_id, String glass_id, String grade){
		this.type = type;
		this.cst_id = cst_id;
		this.glass_id = glass_id;
		this.grade = grade;
	}
	
	
	public void setType(int type){
		this.type = type;
	}

	public void setCst_id(String cst_id) {
		this.cst_id = cst_id;
	}

	public void setGlass_id(String glass_id) {
		this.glass_id = glass_id;
	}

	public void setGrade(String grade){
		this.grade = grade;
	}
	
	
	public int getType(){
		return this.type;
	}
	
	public String getCst_id() {
		return this.cst_id;
	}
	
	public String getGlass_id() {
		return this.glass_id;
	}
	
	public String getGrade(){
		return this.grade;
	}
	
	
	public static int countNG(Module module1,Module module2){
		int count = 0;
		
		//ONLY TFT & CF
		if(module1.getType() != module2.getType()){
			for(int i = 0; i < module1.getGrade().length(); i++){
				if(module1.getGrade().charAt(i) == 'X' || module2.getGrade().charAt(i) == 'X'){
					count++;
				}
			}
		}
		else{
			count = -1;
		}
		
		return count;
	}
	
	public int size(){
		return this.getGrade().length();
	}
	
	
	public static int countNG(Module module){
		int count = 0;
		
		for(int i = 0; i < module.getGrade().length(); i++){
			if(module.getGrade().charAt(i) == 'X'){
				count ++;
			}
		}
		
		return count;
	}
	
	//TODO FOR TESTING ONLY,IGNORE THIS IN PRODUCTION.
	public String toString(){
		return (this.type == Module.MODULE_TYPE_TFT ? "TFT" : "CF ") + "[cst_id = " + this.getCst_id()  + " glass_id = " + this.getGlass_id()+ " grade = " + this.getGrade() + "]"; 
	}
}
